package com.intellij.licensecommon.data;

import com.intellij.licensecommon.util.SubscriptionLicenseDecoder;
import com.intellij.licensecommon.util.SubscriptionLicenseInfo;
import com.intellij.licensecommon.util.a;

import java.util.Date;

public class SubscriptionLicense extends AbstractSubscriptionLicense implements h {
    private final LicenseKeyDecoder<SubscriptionLicenseInfo> decoder;

    public SubscriptionLicense(String key, String username) {
        super(key, username);
        this.decoder = new LicenseKeyDecoder() {
            public SubscriptionLicenseInfo decodeLicenseKey(String licenseKey, String username) throws a {
                return SubscriptionLicenseDecoder.decodeLicenseKey(licenseKey, username);
            }
        };
    }

    public SubscriptionLicense(String key, String username, LicenseKeyDecoder<SubscriptionLicenseInfo> decoder) {
        super(key, username);
        this.decoder = decoder;
    }

    @Override
    protected SubscriptionLicenseInfo getLicenseInfo() throws a {
        return (SubscriptionLicenseInfo) this.decoder.decodeLicenseKey(getKey(), getUsername());
    }

    @Override
    protected SubscriptionLicenseInfo getDefaultLicenseInfo() {
        return SubscriptionLicenseInfo.DEFAULT_LICENSE;
    }

    public Date getUpgradeDueDate() {
        ensureLicenseInfo();
        return ((SubscriptionLicenseInfo) this.LicenseInfo).maintenanceDueDate;
    }
}
